package com.liming.auth.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liming.auth.mapper.AdminRoleMapper;
import com.liming.auth.service.AdminRoleService;
import com.liming.common.pojo.entity.authinfo.AdminRole;
import com.liming.common.util.mybatisplus.MPUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liming
 * @date 2025/1/20
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole>
        implements AdminRoleService, MPUtil<AdminRole> {
    @Override
    public List<Long> listByAdminId(Long adminId) {
        return lambdaQuery().eq(AdminRole::getAdminId, adminId).list().stream().map(AdminRole::getRoleId).toList();
    }

    @Override
    public Boolean removeByRoleId(Long id) {
        List<AdminRole> list = lambdaQuery().eq(AdminRole::getRoleId, id).list();
        if (CollUtil.isEmpty(list)) {
            return true;
        }
        return lambdaUpdate().eq(AdminRole::getRoleId, id).remove();
    }

    @Override
    public List<Long> roleIdsByAdminId(String adminId) {
        return lambdaQuery().eq(AdminRole::getAdminId, adminId).list().stream().map(AdminRole::getRoleId).toList();
    }
}
